package net.alan.modules.repository;

import net.alan.modules.bean.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Author 李岩飞
 * Email eliyanfei@126.com
 * 2017/11/22
 */
public interface ProjectRepository extends JpaRepository<Project, Integer> {

    /**
     * 根据用户名获取组
     * @param userId
     * @return
     */
    @Query(value = "select g.* from project g left join userproject u on g.id = u.project_id  where u.user_id=?1 and g.deleted=0", nativeQuery = true)
    List<Project> findByUserId(Integer userId);

    /**
     * 根据用户获取项目数量
     * @param userId
     * @return
     */
    Integer countByUserIdAndDeletedTrue(Integer userId);
}
